<template>
  <div>
    <button @click="getStudents">获取学生信息</button>
    <button @click="getCars">获取汽车信息</button>
  </div>
</template>

<script>
import axios from 'axios';
export default {
  name: "App",
  methods: {
    // 一共配置了两个文件：app.vue，vue.config
    // public文件夹：car.js，student.js分别为两个服务端
    getStudents () {
      axios.get('/api/student') //其实这里就是请求http://localhost:8080/student只不过把请求转移给了端口5001，省略了协议以及主机
        // 可选择
        // 请求5000，也可以写为http://localhost:8080/api/student
        // 请求本地资源，则可以写为http://localhost:8080/student
        .then(res => console.log(res.data))//res和e均是对象
        .catch(e => console.log(`msg: ${e.message}, stack: ${e.stack}`));
    },
    getCars () {
      axios.get('/demo/car') //同理
        .then(res => console.log(res.data))
        .catch(e => console.log(`msg: ${e.message}, stack: ${e.stack}`));
    }
  }
}
</script>



